'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	let {key,value} = event
	const db = uniCloud.database()
  if(key == 'tags'){
    const { affectedDocs, data} = await db.collection("books").where({tags:value}).get()
    if( affectedDocs == 0){
      return {
        code:0,
        msg:'没有该分类数据'
      }
    }
    else return{
      code:1,
      data
    }
  }
  else{
    const { affectedDocs, data} = await  db.collection("books").where({
    name: new RegExp(value, 'gim')
    }).get()
    if( affectedDocs == 0){
      return {
        code:0,
        msg:'没有找到数据'
      }
    }
    else return{
      code:1,
      data
    }
  }
	
	
};
